"use strict";

import { reactive } from 'vue'

const state = reactive({
	language: localStorage.getItem('lang') || 'zh'
})

const messages = {
	zh: {
		appTitle: '小麦品质检测',
		home: '首页',
		about: '关于我们',
		detection: '检测方法',
		comparison: '品质对比',
		evaluation: '品质评价',
		map: '数字地图',
		news: '新闻中心',
		admin: '后台管理',
		logout: '退出',
		login: '登录',
		register: '注册',
		breadcrumbHome: '首页',
		breadcrumbNews: '新闻中心',
		publishNews: '发布新闻',
		searchPlaceholder: '搜索新闻标题',
		panelManage: '院网信息发布与管理',
		panelLatest: '最新动态',
		view: '查看',
		delete: '删除',
		// form labels
		titleLabel: '标题',
		categoryLabel: '分类',
		typeLabel: '类型',
		mediaSource: '媒体来源',
		uploadFile: '上传文件',
		urlLink: '外链URL',
		imageLabel: '图片',
		videoLabel: '视频',
		imageUrlLabel: '图片URL',
		videoUrlLabel: '视频URL',
		contentLabel: '内容',
		summaryLabel: '摘要',
		authorLabel: '作者',
		sourceLabel: '来源',
		tagsLabel: '标签',
		publishDateLabel: '发布日期',
		pinLabel: '置顶',
		statusLabel: '状态',
		// buttons
		btnPreview: '预览',
		btnReset: '重置',
		btnSaveDraft: '保存草稿',
		btnCancel: '取消',
		btnPublish: '发布',
		btnSelectImages: '选择图片（最多9张）',
		btnSelectVideo: '选择视频',
		btnImportUrl: '导入URL',
		btnInsert: '插入',
		contentInsertTitle: '将下列图片插入正文：',
		autoTranslate: '自动翻译为英文',
		titleEnLabel: '英文标题',
		summaryEnLabel: '英文摘要',
		contentEnLabel: '英文内容',
		// placeholders
		titlePlaceholder: '请输入新闻标题',
		categoryPlaceholder: '请选择分类',
		contentPlaceholder: '请输入新闻正文，支持在正文末尾插入已上传的图片',
		videoUrlPlaceholder: '请输入视频URL',
		imagesUrlPlaceholder: '每行一条图片URL',
		authorPlaceholder: '作者/编辑者',
		sourcePlaceholder: '文章来源（可选）',
		tagsPlaceholder: '输入并回车创建标签',
		// Home
		coreFeatures: '核心功能',
		featureAboutTitle: '公司简介',
		featureAboutDesc: '了解我们的专业团队、核心优势和服务范围',
		featureNewsTitle: '新闻中心',
		featureNewsDesc: '实时更新小麦品质相关新闻、技术动态和行业资讯',
		featureDetectTitle: '检测方法',
		featureDetectDesc: '专业的小麦品质检测方法，包含多项重要指标',
		homeBanner1Title: '专业小麦品质检测',
		homeBanner1Desc: '采用先进技术，提供准确可靠的小麦品质检测服务',
		homeBanner2Title: '科学检测方法',
		homeBanner2Desc: '涵盖蛋白质、湿面筋、粉质参数等多项重要指标',
		latestSection: '最新动态',
		// About
		aboutHeroTitle: '中国小麦品质检测',
		aboutHeroSubtitle: '专业的小麦品质检测服务，为农业发展和食品安全保驾护航',
		statsYears: '年专业经验',
		statsProjects: '检测项目',
		statsPartners: '合作机构',
		aboutUs: '关于我们',
		aboutPara1: '我们是一家专业的小麦品质检测机构，致力于为农业产业链提供科学、准确、可靠的检测服务。自成立以来，我们始终坚持"科学检测、诚信服务"的理念，为保障食品安全和农业可持续发展贡献力量。',
		aboutPara2: '我们拥有先进的检测设备和专业的技术团队，具备完善的质量管理体系，能够为客户提供从样品采集到报告出具的全流程服务。我们的检测结果得到国内外权威机构的认可，为小麦品质评价和贸易提供重要依据。',
		advantages: '核心优势',
		advEquip: '先进设备',
		advEquipDesc: '配备国际先进的检测仪器，确保检测精度和效率',
		advTeam: '专业团队',
		advTeamDesc: '拥有经验丰富的技术专家，提供专业的技术支持',
		advCert: '权威认证',
		advCertDesc: '获得多项国际认证，检测结果具有权威性和公信力',
		advService: '优质服务',
		advServiceDesc: '提供一站式检测服务，快速响应客户需求',
		services: '服务范围',
		serviceQuality: '小麦品质检测',
		serviceNutrition: '营养指标检测',
		serviceSafety: '安全指标检测',
		contactUs: '联系我们',
		address: '地址',
		addressText: '北京市海淀区中关村大街1号',
		phone: '电话',
		email: '邮箱',
		workHours: '工作时间',
		workHoursText: '周一至周五 9:00-18:00',
		onlineConsult: '在线咨询',
		name: '姓名',
		namePlaceholder: '请输入您的姓名',
		phonePlaceholder: '请输入您的联系电话',
		emailPlaceholder: '请输入您的邮箱地址',
		message: '留言',
		messagePlaceholder: '请输入您的咨询内容',
		submitConsult: '提交咨询',
		consultSubmitted: '咨询信息已提交，我们会尽快与您联系！',
		// Detection
		detectionSubtitle: '专业的小麦品质检测方法，涵盖多项重要指标',
		sectionQualityIndicators: '小麦品质指标',
		sectionNutritionIndicators: '小麦营养指标',
		sectionProcess: '检测流程',
		labelMethod: '检测方法：',
		labelRange: '标准范围：',
		labelImportance: '重要性：',
		// confirm & messages
		confirmTitle: '提示',
		confirmDeleteText: '确定要删除这条新闻吗？',
		okText: '确定',
		cancelText: '取消',
		msgOnlyImageVideo: '仅支持图片或视频文件',
		msgMaxImages: '最多可选择 9 张图片',
		msgMaxOneFile: '仅能选择 1 个视频文件',
		msgDraftSaved: '草稿已保存',
		msgInsertOk: '图片已插入正文末尾',
		msgDeleted: '删除成功！',
		msgFillTitle: '请先填写标题',
		msgPleaseComplete: '请完善标题、内容并选择媒体文件',
		msgNeedImageUrl: '请先输入图片URL',
		msgPublished: '发布成功！'
	},
	en: {
		appTitle: 'Wheat Quality Detection',
		home: 'Home',
		about: 'About',
		detection: 'Detection',
		comparison: 'Comparison',
		evaluation: 'Evaluation',
		map: 'Digital Map',
		news: 'News',
		admin: 'Admin',
		logout: 'Logout',
		login: 'Login',
		register: 'Register',
		breadcrumbHome: 'Home',
		breadcrumbNews: 'News',
		publishNews: 'Publish News',
		searchPlaceholder: 'Search news title',
		panelManage: 'Portal Publishing & Management',
		panelLatest: 'Latest',
		view: 'View',
		delete: 'Delete',
		// form labels
		titleLabel: 'Title',
		categoryLabel: 'Category',
		typeLabel: 'Type',
		mediaSource: 'Media Source',
		uploadFile: 'Upload',
		urlLink: 'URL',
		imageLabel: 'Image',
		videoLabel: 'Video',
		imageUrlLabel: 'Image URL',
		videoUrlLabel: 'Video URL',
		contentLabel: 'Content',
		summaryLabel: 'Summary',
		authorLabel: 'Author',
		sourceLabel: 'Source',
		tagsLabel: 'Tags',
		publishDateLabel: 'Publish Date',
		pinLabel: 'Pin to top',
		statusLabel: 'Status',
		// buttons
		btnPreview: 'Preview',
		btnReset: 'Reset',
		btnSaveDraft: 'Save Draft',
		btnCancel: 'Cancel',
		btnPublish: 'Publish',
		btnSelectImages: 'Select images (up to 9)',
		btnSelectVideo: 'Select video',
		btnImportUrl: 'Import URLs',
		btnInsert: 'Insert',
		contentInsertTitle: 'Insert the following images into content:',
		autoTranslate: 'Auto translate to English',
		titleEnLabel: 'Title (EN)',
		summaryEnLabel: 'Summary (EN)',
		contentEnLabel: 'Content (EN)',
		// placeholders
		titlePlaceholder: 'Enter title',
		categoryPlaceholder: 'Select category',
		contentPlaceholder: 'Enter news content; you may append uploaded images to the end',
		videoUrlPlaceholder: 'Enter video URL',
		imagesUrlPlaceholder: 'One image URL per line',
		authorPlaceholder: 'Author/Editor',
		sourcePlaceholder: 'Source (optional)',
		tagsPlaceholder: 'Type and press Enter to create tags',
		// Home
		coreFeatures: 'Core Features',
		featureAboutTitle: 'About Us',
		featureAboutDesc: 'Learn about our expert team, strengths, and services',
		featureNewsTitle: 'News Center',
		featureNewsDesc: 'Real-time updates on wheat quality, technology and industry',
		featureDetectTitle: 'Detection Methods',
		featureDetectDesc: 'Professional wheat quality detection with key indicators',
		homeBanner1Title: 'Professional Wheat Quality Testing',
		homeBanner1Desc: 'Advanced technology delivering accurate, reliable results',
		homeBanner2Title: 'Scientific Detection Methods',
		homeBanner2Desc: 'Covers protein, wet gluten, farinograph parameters and more',
		latestSection: 'Latest Updates',
		// About
		aboutHeroTitle: 'China Wheat Quality Detection',
		aboutHeroSubtitle: 'Professional services safeguarding agriculture and food safety',
		statsYears: 'Years Experience',
		statsProjects: 'Test Items',
		statsPartners: 'Partners',
		aboutUs: 'About Us',
		aboutPara1: 'We are a professional wheat quality testing institute providing scientific, accurate and reliable services for the agricultural value chain. Since inception, we have adhered to "scientific testing, honest service" to support food safety and sustainable agriculture.',
		aboutPara2: 'With advanced instruments and an expert team, we offer end-to-end services from sampling to reporting. Our results are recognized by authorities worldwide and support evaluation and trade of wheat quality.',
		advantages: 'Our Advantages',
		advEquip: 'Advanced Instruments',
		advEquipDesc: 'Equipped with international-grade instruments for precision and efficiency',
		advTeam: 'Expert Team',
		advTeamDesc: 'Experienced specialists providing professional technical support',
		advCert: 'Authoritative Certification',
		advCertDesc: 'Multiple international certifications ensure credibility and trust',
		advService: 'Quality Service',
		advServiceDesc: 'One-stop solutions with fast response to customer needs',
		services: 'Services',
		serviceQuality: 'Wheat Quality Testing',
		serviceNutrition: 'Nutrition Testing',
		serviceSafety: 'Safety Testing',
		contactUs: 'Contact Us',
		address: 'Address',
		addressText: 'No. 1 Zhongguancun St, Haidian, Beijing',
		phone: 'Phone',
		email: 'Email',
		workHours: 'Working Hours',
		workHoursText: 'Mon–Fri 9:00–18:00',
		onlineConsult: 'Online Inquiry',
		name: 'Name',
		namePlaceholder: 'Your name',
		phonePlaceholder: 'Your phone number',
		emailPlaceholder: 'Your email address',
		message: 'Message',
		messagePlaceholder: 'Your inquiry',
		submitConsult: 'Submit',
		consultSubmitted: 'Inquiry submitted. We will contact you shortly.',
		// Detection
		detectionSubtitle: 'Professional wheat quality detection covering key indicators',
		sectionQualityIndicators: 'Wheat Quality Indicators',
		sectionNutritionIndicators: 'Wheat Nutrition Indicators',
		sectionProcess: 'Detection Process',
		labelMethod: 'Method: ',
		labelRange: 'Range: ',
		labelImportance: 'Importance: ',
		// confirm & messages
		confirmTitle: 'Confirm',
		confirmDeleteText: 'Delete this news item?',
		okText: 'OK',
		cancelText: 'Cancel',
		msgOnlyImageVideo: 'Only image or video files are supported',
		msgMaxImages: 'You can select up to 9 images',
		msgMaxOneFile: 'Only one video file is allowed',
		msgDraftSaved: 'Draft saved',
		msgInsertOk: 'Image inserted at the end',
		msgDeleted: 'Deleted successfully',
		msgFillTitle: 'Please enter the title first',
		msgPleaseComplete: 'Please complete title, content, and media',
		msgNeedImageUrl: 'Please input image URLs first',
		msgPublished: 'Published successfully'
	}
}

const categoryMap = {
	'全部': 'All',
	'综合': 'General',
	'图片新闻': 'Photo News',
	'时政要闻': 'Politics',
	'农科要闻': 'Agri Science',
	'科研活动': 'Research',
	'三农一线': 'Rural Front',
	'媒体报道': 'Media',
	'视频农科': 'Agri Videos',
	'政务新媒体矩阵': 'Gov New Media'
}

const I18nPlugin = {
	install(app) {
		// 初始化 html lang 属性
		document.documentElement.setAttribute('lang', state.language)
		app.config.globalProperties.$t = (key) => {
			const pack = messages[state.language] || messages.zh
			return pack[key] || key
		}
		app.config.globalProperties.$setLang = (code) => {
			if (code !== 'zh' && code !== 'en') return
			state.language = code
			localStorage.setItem('lang', code)
			document.documentElement.setAttribute('lang', code)
		}
		app.config.globalProperties.$lang = state
		app.config.globalProperties.$tCategory = (zhName) => {
			if (state.language === 'zh') return zhName || ''
			return categoryMap[zhName] || zhName || ''
		}
	}
}

export default I18nPlugin
export { I18nPlugin }

